using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Linq;
using System.Linq;


using Soussous.Business;
using Soussous.DAO;
using Soussous.DAO.Connection;

namespace Soussous.DAO.Impl
{
    class ParticipantDAO : AbstractDAO<Participant>
    {
        private static ParticipantDAO INSTANCE = new ParticipantDAO();

        public static ParticipantDAO getInstance()
        {
            return INSTANCE;
        }

        private ParticipantDAO()
        {
        }
		
		public Table<Participant> getTable(){
			
			return ParticipantDAO.getInstance().getAll();
		
		}
        
        public List<Participant> getAllParticipant() 
        {


            var ParticipantList = from e in getTable()
                                  select e;
            
            return ParticipantList.ToList();
        }
		
		public List<Participant> searchByUserAndNote(int idUser,int idNote)
		{

            var ParticipantList = from e in getTable()
                           where e.Users_id == idUser && e.Notes_id == idNote
                           select e;
			
			
			return ParticipantList.ToList();
		}
		
		public void updateByUserAndNote(int idUser,int idNote,Participant participant) {

            Table<Participant> part = getTable();
            var update = part.First(e => e.Notes_id == idNote && e.Users_id == idUser);
            update.Amount = participant.Amount;
            part.Context.SubmitChanges();
        
		}
        public void deleteOpeByUserAndNote(int idUser, int idNote)
        {
            Table<Participant> payers = getTable();
            var result = (from e in payers
                          where e.Notes_id == idNote && e.Users_id == idUser
                          select e);
            payers.DeleteOnSubmit(result.Single());
            payers.Context.SubmitChanges();
        }
       
    }
}